package com.zzyl.nursing.controller.member;

import cn.hutool.db.Page;
import cn.hutool.http.cookie.ThreadLocalCookieStore;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.domain.FamilyMemberElder;
import com.zzyl.nursing.dto.MemberElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceDataService;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.*;
import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    /**
     * 绑定家人
     * @param memberElderDto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public R bindFamily(@RequestBody MemberElderDto memberElderDto){
        familyMemberService.bindFamily(memberElderDto);
        return R.ok();
    }

    /**
     * 查询已绑定老人列表
     */
    @GetMapping("/list-by-page")
    @ApiOperation("查询已绑定老人列表")
    public R<List<MemberElderVo>> listByPage(IPage page){
        List<MemberElderVo> listByPage = this.familyMemberService.listByPage(page);
        return R.ok(listByPage);
    }

    /**
     * 查询家属列表
     */
    @GetMapping("/my")
    @ApiOperation("查询家属列表")
    public R<List<FamilyMemberElder>> myPage(){
        List<FamilyMemberElder> familyMemberElderList = this.familyMemberService.myPage();
        return R.ok(familyMemberElderList);
    }

    /**
     * 查询健康数据
     */
    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询健康数据")
    public R<List<DevicePropertyStatusInfo>> queryServiceProperties(@PathVariable String iotId){
        List<DevicePropertyStatusInfo> propertyStatusInfos = this.familyMemberService.queryServiceProperties(iotId);
        return R.ok(propertyStatusInfos);
    }

    /**
     * 按天统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("查询健康数据")
    public R<List<DeviceDataGraphVo>> queryDeviceDataListByDay(
            @Param("iotId") String iotId,
            @Param("functionId") String functionId,
            @Param("startTime") LocalDateTime startTime,
            @Param("endTime") LocalDateTime endTime
    ){
        List<DeviceDataGraphVo> deviceDataGraphVos = this.familyMemberService.queryDeviceDataListByDay(iotId,functionId,startTime,endTime);
        return R.ok(deviceDataGraphVos);
    }

    /**
     * 按周统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("查询健康数据")
    public R<List<DeviceDataGraphVo>> queryDeviceDataListByWeek(
            @Param("iotId") String iotId,
            @Param("functionId") String functionId,
            @Param("startTime") LocalDateTime startTime,
            @Param("endTime") LocalDateTime endTime
    ){
        List<DeviceDataGraphVo> deviceDataGraphVos = this.familyMemberService.queryDeviceDataListByWeek(iotId,functionId,startTime,endTime);
        return R.ok(deviceDataGraphVos);
    }



}
